﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace TCP_IP_Spike
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("IP-address for this instance: ");
            var ip = Console.ReadLine();
            Console.Write("Port to listen on: ");
            var port = Convert.ToInt16(Console.ReadLine());

            var tcpEngine = new TcpEngine(ip, port);
            new Thread(tcpEngine.TcpServerThread).Start();

            Console.Write("Type listen to set client to listen ");
            if (Console.ReadLine() == "listen")
            {
                Console.WriteLine("::Listening for TCP connections::");
                while (true)
                {
                    while (tcpEngine.RxQueue.Count > 0)
                    {
                        Console.WriteLine(tcpEngine.RxQueue.Dequeue().ToString());
                    }
                }
            }
            else
            {
                Console.WriteLine("::Sending format \"*ip-addres*@*port*@*message*\"::");
                while (true)
                {
                    tcpEngine.TxQueue.Enqueue(Console.ReadLine()); 
                }
            }
        }
    }
}
